1 #include<iostream>
2 #include<string.h>
3 #include<conio.h>
4 #include<math.h>
5 #include<fstream>
6 using namespace std;
7 int i,n;
8 ifstream fin;
9 ofstream fout;
10 fstream fio;
11 void disp();
12 class stock
13 {
14 char name[20],pass[10];
15 float pr; int quant;
16
17 public:
18 void get();
19 void get2();
20 void show();
21 int stchk(char nm[30]);
22 void withd(int qty);
23 void refil(int qty);
24 }st;
25 void stock::withd(int qty)
26 {
27 if(quant>=qty)
28 {
29 quant-=qty;
30 cout<<"\n\nStock updated.\n";
31 cout<<"\n\nTotal price to be paid:"<<pr*qty;
32 }
33 else
34 cout<<"\n\nInsufficient stock";
35 getch();
36
37
38 }
39
40 void stock::refil(int qty)
41 {
42
43 quant+=qty;
44 cout<<"\n\nStock updated.";
45 getch();
46
47
48 }
49 int stock::stchk(char nm[30])
50 {
51 if(strcmp(nm,name)==0)
52 return 0;
53 else
54 return 1;
55 }
56 void stock::get()
57 {
58 cin>>name>>pr>>quant;
59 /*cout<<"\n\nEnter the password letter by letter\n";
60
61 for(int z=0;z<5;z++)
62 {
63
64 cin>>pass[z];
65 system("cls");
66 cout<<"\n\nEnter the password letter by letter\n";
67 for(i=1;i<=(z+1);i++)
68 {
69 cout<<"*";
70 }
71 }
72 if(strcmp(pass,"hello")==0)
73 {
74 cout<<"\nCongrats!!Access Granted!!\n\n";
75 cout<<"\nEnter the Name followed By the price and then by the quantity\n";
76 cin>>name>>pr>>quant;
77 }
78 else
79 cout<<"Access Denied!!";*/
80 }
81 void stock::get2()
82 {
83 cin>>name>>quant;
84 }
85
86 void stock::show()
87 {
88
89 cout<<"\n"<<name<<"\t\t\t"<<quant<<"\t\t\t"<<pr;
90 }
91 void addnew()
92 {
93 // cout<<"\n\n\nCongrats!!Access Granted!!\n\n";
94
95 system("cls");
96 //cout<<"\nEnter the Name followed By the price and then by the quantity\n";
97 disp();
98 getch();
99 system("cls");
100
101 cout<<"\nEnter the No. of Products that you wish to add: ";
102 cin>>n;
103
104
105 if (n!=0)
106 {
107
108 int j,l,sum=0;
109 fout.open("shop.dat",ios::binary|ios::app);
110 for(i=0;i<n;i++)
111
112 {
113 /*if(i==0)
114 {
115 system("cls");
116 }*/
117 cout<<"\n\nInput the name, price and the quantity of item respectively\n\n";
118 st.get();
119 fout.write((char*)&st,sizeof(st));
120 cout<<"\n\nitem updated";
121 cin.get();
122
123
124 }
125 cout<<"\n\nStock Updated!!";
126
127
128 fout.close();
129 cin.get();
130 system("cls");
131 disp();
132 }
133
134 else
135 {
136
137 fout.close();
138 cin.get();
139 system("cls");
140 cout<<"\n\nNo items to be added";
141
142 }
143 }
144
145
146
147
148 void withdraw()
149 {
150 system("cls");
151 char temp[100];int qty;
152 int i=0;
153 long pos=0;
154 disp();
155 cout<<"\n\nEnter the product's name \n"<<endl;
156 cin>>temp;
157 cout<<"\n\nEnter quantity: \n"<<endl;
158 cin>>qty;
159 fio.open("shop.dat",ios::binary|ios::out|ios::in);
160 while(fio)
161 {
162 pos=fio.tellp();
163 fio.read((char*)&st,sizeof(st));
164 if(st.stchk(temp)==0)
165 {
166
167 st.withd(qty);
168 fio.seekp(pos);
169 fio.write((char*)&st,sizeof(st));
170 i++;break;
171 }
172 }
173
174
175 if(i!=1)
176 cout<<"\n\n!!Record not found!!";
177 fio.close();
178 cin.get();
179 system("cls");
180 disp();
181 getch();
182 }
183 void disp()
184 {
185 int i=1;
186 cout<<"\n==================================================================";
187 cout<<"\n\n=================\tTHE STOCK ITEMS ARE\t==================";
188 cout<<"\n\n==================================================================\n";
189 cout<<"\n\nPARTICULARS\tSTOCK AVAILABLE\t\t\t PRICE";
190 cout<<"\n\n============================================================\n";
191 fin.open("shop.dat",ios::binary);
192 while(!fin.eof())
193 {
194 fin.read((char*)&st,sizeof(st));
195 if(!fin.eof())
196 {
197 if(fin.tellg()<0)
198 { i=0; break;}
199 st.show();
200 }
201 }
202 if(i==0)
203 { cout<<"\n\n\t\t\t!!Empty record room!!";
204 getch();
205 }
206 fin.close();
207
208 }
209 void refill()
210 {
211 system("cls");
212 char temp[100];int qty;
213 int i=0;
214 long pos=0;
215 disp();
216 cout<<"\n\nEnter the products name \n"<<endl;
217 cin>>temp;
218 cout<<"\n\nEnter quantity: \n"<<endl;
219 cin>>qty;
220 fio.open("shop.dat",ios::binary|ios::out|ios::in);
221 while(fio)
222 {
223 pos=fio.tellp();
224 fio.read((char*)&st,sizeof(st));
225 if(st.stchk(temp)==0)
226 {
227
228 st.refil(qty);
229 fio.seekp(pos);
230 fio.write((char*)&st,sizeof(st));
231 i++;break;
232 }
233 }
234 if(i!=1)
235 cout<<"\n\n!!Record not found!!";
236 fio.close();
237 system("cls");
238 cin.get();
239 disp(); cin.get();
240
241
242 }
243 void remove()
244 {
245 system("cls");
246 int i=0;
247 char temp[30];
248 cout<<"\n\t\t\t\tDelete Record";
249 cout<<"\n\nEnter the name of the product:";
250 cin>>temp;
251 fout.open("temp.dat",ios::binary);
252 fin.open("shop.dat",ios::binary);
253 while(!fin.eof())
254 {
255 fin.read((char*)&st,sizeof(st));
256 if(!fin.eof())
257 if(st.stchk(temp)==0)
258 {
259 st.show();
260 cout<<"\n\n\t\tRecord deleted";
261 i++;
262 }
263 else
264 fout.write((char*)&st,sizeof(st));
265 }
266 if(i==0)
267 cout<<"\n\n!!Record not found!!";
268 fin.close();
269 fout.close();
270 remove("shop.dat");
271 rename("temp.dat","shop.dat");
272 }
273 int main()
274 {
275 char pass[10],pass2[10];
276 int i,j;
277 cout<<"\n\n\n\n\n\n\n\n\n\n\n \t\t\t|============ WELCOME TO STORE MANAGEMENT ============|";
278 getch();
279 system("cls");
280 cout<<"\n\t\t STORE MANAGEMENT SYSTEM\n";
281 cout<<"=============================================================";
282 cout<<"\n\n\t\t 1. Dealer Menu\n\n\t\t 2. Customer Menu\n\n\t\t 3. Employee Menu";
283 cout<<"\n\n=============================================================\n";
284 cout<<"\n\nEnter Your Choice:";
285 cin>>j;
286 if(j==1)
287 {
288
289 system("cls");
290 /*disp();
291
292 cout<<"\n\n\n\nEnter the No. of Products that you wish to add: ";
293 cin>>n;*/
294 system("cls");
295 cout<<"\n\n\n\n\n\n\n\t\t\t\t\tEnter the password letter by letter: ";
296
297 for(int z=0;z<6;z++)
298 {
299 pass[z]=getch();
300 system("cls");
301 cout<<"\n\n\n\n\n\n\n\t\t\t\t\tEnter the password letter by letter: ";
302 for(i=1;i<=(z+1);i++)
303 {
304 cout<<"*";
305 }
306 }
307 if(strcmp(pass,"dealer")==0)
308 {
309 /*cout<<"\n\n\nCongrats!!Access Granted!!\n\n";
310 getch();*/
311 system("cls");
312 dealermenu:
313 system("cls");
314 cout<<"=================================================================";
315 cout<<"\n\n\t\t\t DEALER MENU\n1. Add new product\n2. Display stock\n3. Refill\n4. Remove an item\n5. Exit:";
316 cout<<"\n\n\n==========================END OF MENU=============================";
317 cout<<"\n\n Enter your Choice :\t";
318 cin>>i;
319 if(i==1)
320 {
321 addnew();getch();
322 goto dealermenu;
323 }
324
325 else if(i==2)
326 {
327 system("cls");
328 disp();getch();goto dealermenu;
329 }
330 else if(i==3)
331 {
332 refill();goto dealermenu;
333 }
334 else if(i==4)
335 {
336 remove();getch();goto dealermenu;
337 }
338 else
339 {
340 system("cls");
341 cout<<"\n\n\n\t\t\tBrought To You By code-projects.org";
342 getch();
343 exit(0);
344 }
345 }
346 else
347 {
348 cout<<"\n\n\nAuthorised Personnel Only\n\n";
349 getch();
350 getch();
351 getch();
352 getch();
353 getch();
354 getch();
355 exit(0);
356 }
357 }
358 if(j==2)
359 {
360 custmenu:
361 system("cls");
362 cout<<"=================================================================";
363 cout<<"\n\n\t\t\t CUSTOMER MENU\n1. Purchase\n2. Display stock\n3. Exit:";
364 cout<<"\n\n\n==========================END OF MENU=============================";
365 cout<<"\n\n Enter your Choice :\t";
366 cin>>i;
367
368
369
370 if (i==1)
371 {
372 withdraw();getch();goto custmenu;
373 }
374 else if(i==2)
375 {
376 system("cls");
377 disp();getch();goto custmenu;
378 }
379
380 else
381 {
382 system("cls");
383 cout<<"\n\n\n\t\t\tBrought To You By code-projects.org";
384 getch();
385 exit(0);
386 }
387
388 }
389 if(j==3)
390
391 {
392 system("cls");
393 cout<<"\n\n\n\n\n\n\n\t\t\t\t\tEnter the password letter by letter: ";
394
395 for(int z=0;z<3;z++)
396 {
397 pass2[z]=getch();
398 system("cls");
399 cout<<"\n\n\n\n\n\n\n\t\t\t\t\tEnter the password letter by letter: ";
400 for(i=1;i<=(z+1);i++)
401 {
402 cout<<"*";
403 }
404 }
405 if(strcmp(pass2,"emp")==0)
406 {
407 empmenu:
408 system("cls");
409 cout<<"=================================================================";
410 cout<<"\n\n\t\t\tEMPLOYEE MENU\n1. Display stock\n2. Refill\n3. Exit";
411 cout<<"\n\n\n==========================END OF MENU=============================";
412 cout<<"\n\n Enter your Choice :\t";
413 cin>>i;
414 if(i==1)
415 {
416 system("cls");
417 disp();getch();goto empmenu;
418 }
419 else if(i==2)
420 {
421 refill();goto empmenu;
422 }
423 else
424 {
425 system("cls");
426 cout<<"\n\n\n\t\t\tThank You!!";
427 getch();
428 exit(0);
429 }
430 }
431 else
432 {
433 cout<<"\n\nSorry!! Access Denied..\n\n";
434 getch();
435 getch();
436 getch();
437 getch();
438 getch();
439
440 exit(0);
441 }
442
443 }
444
445 getch();
446
447 }